<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<meta name="theme-color" content="#222">

<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">






  <script>
  (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/6f697dad.js","daovoice")
  daovoice('init', {
      app_id: "6f697dad"
    });
  daovoice('update');
  </script>















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="教育系统APP,">





  <link rel="alternate" href="/atom.xml" title="达叔小生" type="application/atom+xml">






<meta name="description" content="用一切抱怨的时间去努力">
<meta name="keywords" content="教育系统APP">
<meta property="og:type" content="article">
<meta property="og:title" content="教育系统APP(八)">
<meta property="og:url" content="https://huangguangda.github.io/2018/04/28/1/index.html">
<meta property="og:site_name" content="达叔小生">
<meta property="og:description" content="用一切抱怨的时间去努力">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://huangguangda.github.io/images/35.jpg">
<meta property="og:image" content="https://huangguangda.github.io/images/36.png">
<meta property="og:updated_time" content="2019-01-23T11:59:06.298Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="教育系统APP(八)">
<meta name="twitter:description" content="用一切抱怨的时间去努力">
<meta name="twitter:image" content="https://huangguangda.github.io/images/35.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://huangguangda.github.io/2018/04/28/1/">




<!-- 网页加载条 -->
<script src="https://neveryu.github.io/js/src/pace.min.js"></script>
  <title>教育系统APP(八) | 达叔小生</title>
  









  <!-- 音频播放 -->
<link rel="stylesheet" href="/dist/APlayer.min.css">
<div id="aplayer"></div>
<script type="text/javascript" src="/dist/APlayer.min.js"></script>
<script type="text/javascript" src="/dist/music.js"></script>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <a href="https://github.com/huangguangda" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">达叔小生</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">爱好分享的码农</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-首页">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-关于">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-标签">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-分类">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-归档">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-书籍">
          <a href="/books" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br>
            
            书籍
          </a>
        </li>
      
        
        <li class="menu-item menu-item-电影">
          <a href="/movies" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-chrome"></i> <br>
            
            电影
          </a>
        </li>
      
        
        <li class="menu-item menu-item-站点">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br>
            
            站点
          </a>
        </li>
      
        
        <li class="menu-item menu-item-公益">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br>
            
            公益
          </a>
        </li>
      
        
        <li class="menu-item menu-item-课本">
          <a href="/book/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-apple"></i> <br>
            
            课本
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>


 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://huangguangda.github.io/2018/04/28/1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="达叔小生">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="达叔小生">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">教育系统APP(八)</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-04-28T15:52:36+08:00">
                2018-04-28
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/教育系统APP/" itemprop="url" rel="index">
                    <span itemprop="name">教育系统APP</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本文总阅读量
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  7,082
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  40
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote class="blockquote-center">用一切抱怨的时间去努力</blockquote>

<p><img src="/images/35.jpg" style="width: 100%;height: 100%"></p>
<a id="more"></a>
<h2 id="项目“课程”的模块2"><a href="#项目“课程”的模块2" class="headerlink" title="项目“课程”的模块2"></a>项目“课程”的模块2</h2><h2 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h2><ol>
<li><p>学习目标<br>1.1 掌握课程模块的开发，实现用VideoView完成视频的播放<br>1.2 掌握课程模块的开发，实现用JSONObject完成Json数据的解析<br>1.3 掌握课程模块的开发，实现用数据库保存播放记录    </p>
</li>
<li><p>项目实操<br>2.1 课程详情<br>2.1.1 课程详情界面布局<br>2.1.2 课程详情Item<br>2.1.3 课程详情界面适配器和数据库<br>2.1.4 课程详情界面逻辑代码    </p>
<p>2.2 视频播放<br>2.2.1 视频播放布局<br>2.2.2 视频播放逻辑代码    </p>
<p>2.3 播放记录<br>2.3.1 播放记录布局<br>2.3.2 播放记录item<br>2.3.3 播放记录adapter<br>2.3.4 播放记录逻辑代码</p>
</li>
<li><p>任务实施<br>3.1 json解析<br>3.2 播放网络视频    </p>
</li>
</ol>
<h2 id="学习目标"><a href="#学习目标" class="headerlink" title="学习目标"></a>学习目标</h2><p>1.1掌握课程模块的开发，实现用VideoView完成视频的播放<br>1.2掌握课程模块的开发，实现用JSONObject完成Json数据的解析<br>1.3掌握课程模块的开发，实现用数据库保存播放记录</p>
<p>课程模块主要用于展示课程中的视频信息，当点击课程列表时会跳转到课程详情界面，在该界面中可以播放相应章节的视频。同时为了方便用户查看已学习的视频，还在“我”的界面中添加了一个播放记录。本章将对课程界面进行详细讲解。</p>
<h2 id="项目实操"><a href="#项目实操" class="headerlink" title="项目实操"></a>项目实操</h2><p>课程详情<br>课程详情界面布局<br>把本章所需要的图片放入drawable文件夹中</p>
<p><img src="/images/36.png" alt="36"></p>
<p>在res包下新建一个资源包，命名为raw，放入视频文件video11.mp4 </p>
<p>新建一个布局文件，命名为activity_video_list<br>课程详情布局代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span><br><span class="line">    android:orientation=&quot;vertical&quot;</span><br><span class="line">    android:layout_width=&quot;match_parent&quot;</span><br><span class="line">    android:layout_height=&quot;match_parent&quot;</span><br><span class="line">    android:background=&quot;@android:color/white&quot;&gt;</span><br><span class="line">    &lt;TextView</span><br><span class="line">        android:layout_width=&quot;match_parent&quot;</span><br><span class="line">        android:layout_height=&quot;200dp&quot;</span><br><span class="line">        android:background=&quot;@drawable/default_video_list_icon&quot;/&gt;</span><br><span class="line">    &lt;LinearLayout</span><br><span class="line">        android:layout_width=&quot;match_parent&quot;</span><br><span class="line">        android:layout_height=&quot;50dp&quot;</span><br><span class="line">        android:gravity=&quot;center&quot;</span><br><span class="line">        android:orientation=&quot;horizontal&quot;&gt;</span><br><span class="line">        &lt;RelativeLayout</span><br><span class="line">            android:layout_width=&quot;0dp&quot;</span><br><span class="line">            android:layout_height=&quot;match_parent&quot;</span><br><span class="line">            android:layout_weight=&quot;1&quot;</span><br><span class="line">            android:background=&quot;@drawable/video_list_intro_icon&quot;&gt;</span><br><span class="line">            &lt;TextView</span><br><span class="line">                android:id=&quot;@+id/tv_intro&quot;</span><br><span class="line">                android:layout_width=&quot;match_parent&quot;</span><br><span class="line">                android:layout_height=&quot;46dp&quot;</span><br><span class="line">                android:layout_centerVertical=&quot;true&quot;</span><br><span class="line">                android:background=&quot;#30B4FF&quot;</span><br><span class="line">                android:gravity=&quot;center&quot;</span><br><span class="line">                android:text=&quot;简 介&quot;</span><br><span class="line">                android:textColor=&quot;#FFFFFF&quot;</span><br><span class="line">                android:textSize=&quot;20sp&quot;/&gt;</span><br><span class="line">        &lt;/RelativeLayout&gt;</span><br><span class="line">        &lt;View</span><br><span class="line">            android:layout_width=&quot;1dp&quot;</span><br><span class="line">            android:layout_height=&quot;48dp&quot;</span><br><span class="line">            android:background=&quot;#C3C3C3&quot;/&gt;</span><br><span class="line">        &lt;RelativeLayout</span><br><span class="line">            android:layout_width=&quot;0dp&quot;</span><br><span class="line">            android:layout_height=&quot;match_parent&quot;</span><br><span class="line">            android:layout_weight=&quot;1&quot;</span><br><span class="line">            android:background=&quot;@drawable/video_list_intro_icon&quot;&gt;</span><br><span class="line">            &lt;TextView</span><br><span class="line">                android:id=&quot;@+id/tv_video&quot;</span><br><span class="line">                android:layout_width=&quot;match_parent&quot;</span><br><span class="line">                android:layout_height=&quot;46dp&quot;</span><br><span class="line">                android:layout_centerVertical=&quot;true&quot;</span><br><span class="line">                android:background=&quot;#FFFFFF&quot;</span><br><span class="line">                android:gravity=&quot;center&quot;</span><br><span class="line">                android:text=&quot;视 频&quot;</span><br><span class="line">                android:textColor=&quot;#000000&quot;</span><br><span class="line">                android:textSize=&quot;20sp&quot;/&gt;</span><br><span class="line">        &lt;/RelativeLayout&gt;</span><br><span class="line">    &lt;/LinearLayout&gt;</span><br><span class="line">    &lt;RelativeLayout</span><br><span class="line">        android:layout_width=&quot;match_parent&quot;</span><br><span class="line">        android:layout_height=&quot;match_parent&quot;&gt;</span><br><span class="line">        &lt;ListView</span><br><span class="line">            android:id=&quot;@+id/lv_video_list&quot;</span><br><span class="line">            android:layout_width=&quot;match_parent&quot;</span><br><span class="line">            android:layout_height=&quot;match_parent&quot;</span><br><span class="line">            android:layout_marginLeft=&quot;15dp&quot;</span><br><span class="line">            android:layout_marginRight=&quot;15dp&quot;</span><br><span class="line">            android:divider=&quot;#E4E4E4&quot;</span><br><span class="line">            android:dividerHeight=&quot;1dp&quot;</span><br><span class="line">            android:scrollbars=&quot;none&quot;</span><br><span class="line">            android:visibility=&quot;gone&quot;/&gt;</span><br><span class="line">        &lt;ScrollView</span><br><span class="line">            android:id=&quot;@+id/sv_chapter_intro&quot;</span><br><span class="line">            android:layout_width=&quot;match_parent&quot;</span><br><span class="line">            android:layout_height=&quot;match_parent&quot;&gt;</span><br><span class="line">            &lt;LinearLayout</span><br><span class="line">                android:layout_width=&quot;match_parent&quot;</span><br><span class="line">                android:layout_height=&quot;match_parent&quot;</span><br><span class="line">                android:orientation=&quot;horizontal&quot;&gt;</span><br><span class="line">                &lt;TextView</span><br><span class="line">                    android:id=&quot;@+id/tv_chapter_intro&quot;</span><br><span class="line">                    android:layout_width=&quot;match_parent&quot;</span><br><span class="line">                    android:layout_height=&quot;match_parent&quot;</span><br><span class="line">                    android:lineSpacingMultiplier=&quot;1.5&quot;</span><br><span class="line">                    android:padding=&quot;10dp&quot;</span><br><span class="line">                    android:text=&quot;安卓简介&quot;</span><br><span class="line">                    android:textColor=&quot;@android:color/black&quot;</span><br><span class="line">                    android:textSize=&quot;14sp&quot;/&gt;</span><br><span class="line">            &lt;/LinearLayout&gt;</span><br><span class="line">        &lt;/ScrollView&gt;</span><br><span class="line">    &lt;/RelativeLayout&gt;</span><br><span class="line">&lt;/LinearLayout&gt;</span><br></pre></td></tr></table></figure>
<p>课程详情Item<br>课程详情界面里也有一个课程列表，这里我们用ListView就可以了。<br>新建一个布局文件，命名为video_list_item。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span><br><span class="line">    android:orientation=&quot;horizontal&quot;</span><br><span class="line">    android:layout_width=&quot;match_parent&quot;</span><br><span class="line">    android:layout_height=&quot;wrap_content&quot;</span><br><span class="line">    android:background=&quot;@android:color/white&quot;</span><br><span class="line">    android:gravity=&quot;center_vertical&quot;</span><br><span class="line">    android:paddingBottom=&quot;15dp&quot;</span><br><span class="line">    android:paddingTop=&quot;15dp&quot;&gt;</span><br><span class="line">    &lt;ImageView</span><br><span class="line">        android:id=&quot;@+id/iv_left_icon&quot;</span><br><span class="line">        android:layout_width=&quot;25dp&quot;</span><br><span class="line">        android:layout_height=&quot;25dp&quot;</span><br><span class="line">        android:src=&quot;@drawable/course_bar_icon&quot;/&gt;</span><br><span class="line">    &lt;TextView</span><br><span class="line">        android:id=&quot;@+id/tv_video_title&quot;</span><br><span class="line">        android:layout_width=&quot;wrap_content&quot;</span><br><span class="line">        android:layout_height=&quot;match_parent&quot;</span><br><span class="line">        android:layout_marginLeft=&quot;10dp&quot;</span><br><span class="line">        android:gravity=&quot;center_vertical&quot;</span><br><span class="line">        android:text=&quot;[第一节]Android简介&quot;</span><br><span class="line">        android:textColor=&quot;#333333&quot;</span><br><span class="line">        android:textSize=&quot;14sp&quot;/&gt;</span><br><span class="line">&lt;/LinearLayout&gt;</span><br></pre></td></tr></table></figure>
<p>课程详情界面适配器和数据库<br>先写一个视频的属性类，命名为VideoBean</p>
<p>VideoBean.java<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.Bean;</span><br><span class="line"></span><br><span class="line">public class VideoBean &#123;</span><br><span class="line">    public int chapterId;//章节Id</span><br><span class="line">    public int videoId;//视频Id</span><br><span class="line">    public String videoPath;//视频播放地址</span><br><span class="line">    public String title;//章节标题</span><br><span class="line">    public String secondTitle;//视频标题</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>写完属性类，我们来完善数据库的代码，为后面的播放记录做准备。<br>打开Sqlite包下的SQLiteHelper.java，补充视频表的代码。</p>
<p>SQLiteHelper.java </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.Sqlite;</span><br><span class="line"></span><br><span class="line">import android.content.Context;</span><br><span class="line">import android.database.sqlite.SQLiteDatabase;</span><br><span class="line">import android.database.sqlite.SQLiteOpenHelper;</span><br><span class="line"></span><br><span class="line">public class SQLiteHelper extends SQLiteOpenHelper&#123;</span><br><span class="line">    private static final int DB_VERSION = 1;</span><br><span class="line">    public static String DB_NAME = &quot;bxg.db&quot;;</span><br><span class="line">    public static final String U_USER_INFO = &quot;userInfo&quot;;</span><br><span class="line">    public static final String U_VIDEO_PLAY_LIST=&quot;videoplaylist&quot;;</span><br><span class="line"></span><br><span class="line">    /*public SQLiteHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) &#123;</span><br><span class="line">        super(context, name, factory, version);</span><br><span class="line">    &#125;*/</span><br><span class="line">    public SQLiteHelper(Context context)&#123;</span><br><span class="line">        super(context, DB_NAME, null, DB_VERSION);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void onCreate(SQLiteDatabase db) &#123;</span><br><span class="line">        /**</span><br><span class="line">         * 当这个SQLiteOpenHelper的子类类被实例化时会创建指定名的数据库，在onCreate中创建个人信息表</span><br><span class="line">         * **/</span><br><span class="line">        db.execSQL(&quot;CREATE TABLE IF NOT EXISTS &quot; + U_USER_INFO + &quot;( &quot;</span><br><span class="line">                + &quot;_id  INTEGER PRIMARY KEY AUTOINCREMENT, &quot;</span><br><span class="line">                + &quot;userName VARCHAR, &quot;</span><br><span class="line">                + &quot;nickName VARCHAR, &quot;</span><br><span class="line">                + &quot;sex VARCHAR, &quot;</span><br><span class="line">                + &quot;signature VARCHAR, &quot;</span><br><span class="line">                + &quot;qq VARCHAR &quot;</span><br><span class="line">                + &quot;)&quot;);</span><br><span class="line">        db.execSQL(&quot;CREATE TABLE IF NOT EXISTS &quot; + U_VIDEO_PLAY_LIST + &quot;( &quot;</span><br><span class="line">                + &quot;_id INTEGER PRIMARY KEY AUTOINCREMENT, &quot;</span><br><span class="line">                + &quot;userName VARCHAR, &quot; //用户名</span><br><span class="line">                + &quot;chapterId INT, &quot; //章节</span><br><span class="line">                + &quot;videoId int, &quot;       //小节id</span><br><span class="line">                + &quot;videoPath VARCHAR,&quot;  //视频地址</span><br><span class="line">                + &quot;title VARCHAR,&quot;//视频章节名称</span><br><span class="line">                + &quot;secondTitle VARCHAR&quot;//视频名单</span><br><span class="line">                + &quot;)&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 当数据库版本号增加才会调用此方法</span><br><span class="line">     **/</span><br><span class="line">    @Override</span><br><span class="line">    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) &#123;</span><br><span class="line">        db.execSQL(&quot;DROP TABLE IF EXISTS &quot; + U_USER_INFO);</span><br><span class="line">        db.execSQL(&quot;DROP TABLE IF EXISTS &quot; + U_VIDEO_PLAY_LIST);</span><br><span class="line">        onCreate(db);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>到Utils包下的DBUtils.java中补充操作数据表的方法。</p>
<p>DBUtils.java</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.utils;</span><br><span class="line"></span><br><span class="line">import android.content.ContentValues;</span><br><span class="line">import android.content.Context;</span><br><span class="line">import android.database.Cursor;</span><br><span class="line">import android.database.sqlite.SQLiteDatabase;</span><br><span class="line"></span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Bean.UserBean;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Bean.VideoBean;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Sqlite.SQLiteHelper;</span><br><span class="line"></span><br><span class="line">public class DBUtils &#123;</span><br><span class="line">    private static DBUtils instance = null;</span><br><span class="line">    private static SQLiteHelper helper;</span><br><span class="line">    private static SQLiteDatabase db;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 构造方法，只有当类被实例化时候调用</span><br><span class="line">     * 实例化SQLiteHelper类，从中得到一个课读写的数据库</span><br><span class="line">     **/</span><br><span class="line">    public DBUtils(Context context) &#123;</span><br><span class="line">        helper = new SQLiteHelper(context);</span><br><span class="line">        db = helper.getWritableDatabase();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 得到这个类的实例</span><br><span class="line">     **/</span><br><span class="line">    public static DBUtils getInstance(Context context) &#123;</span><br><span class="line">        if (instance == null) &#123;</span><br><span class="line">            instance = new DBUtils(context);</span><br><span class="line">        &#125;</span><br><span class="line">        return instance;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 保存个人资料信息</span><br><span class="line">     **/</span><br><span class="line">    public void saveUserInfo(UserBean bean) &#123;</span><br><span class="line">        ContentValues cv = new ContentValues();</span><br><span class="line">        cv.put(&quot;userName&quot;, bean.userName);</span><br><span class="line">        cv.put(&quot;nickName&quot;, bean.nickName);</span><br><span class="line">        cv.put(&quot;sex&quot;, bean.sex);</span><br><span class="line">        cv.put(&quot;signature&quot;, bean.signature);</span><br><span class="line">        cv.put(&quot;qq&quot;,bean.qq);</span><br><span class="line">        //Convenience method for inserting a row into the database.</span><br><span class="line">        //注意，我们是从数据库使用插入方法，传入表名和数据集完成插入</span><br><span class="line">        db.insert(SQLiteHelper.U_USER_INFO, null, cv);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 获取个人资料信息</span><br><span class="line">     **/</span><br><span class="line">    public UserBean getUserInfo(String userName) &#123;</span><br><span class="line">        String sql = &quot;SELECT * FROM &quot; + SQLiteHelper.U_USER_INFO + &quot; WHERE userName=?&quot;;</span><br><span class="line">        //?和下面数组内元素会逐个替换，可以多条件查询=?and =?</span><br><span class="line">        //You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs.</span><br><span class="line">        Cursor cursor = db.rawQuery(sql, new String[]&#123;userName&#125;);</span><br><span class="line">        UserBean bean = null;</span><br><span class="line">        //Move the cursor to the next row.</span><br><span class="line">        while (cursor.moveToNext()) &#123;</span><br><span class="line">            bean = new UserBean();</span><br><span class="line">            //根据列索引获取对应的数值，因为这里查询结果只有一个，我们也不需要对模型UserBean进行修改，</span><br><span class="line">            //直接将对应用户名的所有数据从表中动态赋值给bean</span><br><span class="line">            bean.userName = cursor.getString(cursor.getColumnIndex(&quot;userName&quot;));</span><br><span class="line">            bean.nickName = cursor.getString(cursor.getColumnIndex(&quot;nickName&quot;));</span><br><span class="line">            bean.sex = cursor.getString(cursor.getColumnIndex(&quot;sex&quot;));</span><br><span class="line">            bean.signature = cursor.getString(cursor.getColumnIndex(&quot;signature&quot;));</span><br><span class="line">            bean.qq = cursor.getString(cursor.getColumnIndex(&quot;qq&quot;));</span><br><span class="line">        &#125;</span><br><span class="line">        cursor.close();</span><br><span class="line">        return bean;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 修改个人资料信息,这里的key指代表字段，value表示数值</span><br><span class="line">     **/</span><br><span class="line">    public void updateUserInfo(String key, String value, String userName) &#123;</span><br><span class="line">        ContentValues cv = new ContentValues();</span><br><span class="line">        cv.put(key, value);</span><br><span class="line">        //Convenience method for updating rows in the database.</span><br><span class="line">        db.update(SQLiteHelper.U_USER_INFO, cv, &quot;userName=?&quot;, new String[]</span><br><span class="line">                &#123;userName&#125;);</span><br><span class="line">    &#125;</span><br><span class="line">    public void saveVideoPlayList(VideoBean videoBean, String userName)&#123;</span><br><span class="line">        if (hasVideoPlay(videoBean.chapterId, videoBean.videoId, userName))&#123;</span><br><span class="line">            boolean isDelete = delVideoPlay(videoBean.chapterId, videoBean.videoId, userName);</span><br><span class="line">            if (!isDelete)&#123;</span><br><span class="line">                return;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        ContentValues cv = new ContentValues();</span><br><span class="line">        cv.put(&quot;userName&quot;, userName);</span><br><span class="line">        cv.put(&quot;chapterId&quot;, videoBean.chapterId);</span><br><span class="line">        cv.put(&quot;videoId&quot;, videoBean.videoId);</span><br><span class="line">        cv.put(&quot;videoPath&quot;, videoBean.videoPath);</span><br><span class="line">        cv.put(&quot;title&quot;, videoBean.title);</span><br><span class="line">        cv.put(&quot;secondTitle&quot;, videoBean.secondTitle);</span><br><span class="line">        db.insert(SQLiteHelper.U_VIDEO_PLAY_LIST, null, cv);</span><br><span class="line">    &#125;</span><br><span class="line">    private boolean delVideoPlay(int chapterId, int videoId, String userName)&#123;</span><br><span class="line">        boolean delSuccess = false;</span><br><span class="line">        int row = db.delete(SQLiteHelper.U_VIDEO_PLAY_LIST,</span><br><span class="line">                &quot; chapterId=? AND videoId=? AND userName=?&quot;,</span><br><span class="line">                new String[]&#123;chapterId + &quot;&quot;, videoId + &quot;&quot;, userName&#125;);</span><br><span class="line">        if (row &gt; 0)&#123;</span><br><span class="line">            delSuccess = true;</span><br><span class="line">        &#125;</span><br><span class="line">        return delSuccess;</span><br><span class="line">    &#125;</span><br><span class="line">    private boolean hasVideoPlay(int chapterId, int videoId, String userName)&#123;</span><br><span class="line">        boolean hasVideo = false;</span><br><span class="line">        String sql = &quot;SELECT * FROM &quot; + SQLiteHelper.U_VIDEO_PLAY_LIST +</span><br><span class="line">                &quot; WHERE chapterId=? AND videoId=? AND userName=?&quot;;</span><br><span class="line">        Cursor cursor = db.rawQuery(sql, new String[]&#123;chapterId + &quot;&quot;, videoId + &quot;&quot;, userName&#125;);</span><br><span class="line">        if (cursor.moveToNext())&#123;</span><br><span class="line">            hasVideo = true;</span><br><span class="line">        &#125;</span><br><span class="line">        cursor.close();</span><br><span class="line">        return hasVideo;</span><br><span class="line">    &#125;</span><br><span class="line">    public List&lt;VideoBean&gt; getVideoHistory(String s)&#123;</span><br><span class="line">        String sql = &quot;SELECT * FROM &quot; + SQLiteHelper.U_VIDEO_PLAY_LIST + &quot; WHERE userName=?&quot;;</span><br><span class="line">        Cursor cursor = db.rawQuery(sql, new String[]&#123;s&#125;);</span><br><span class="line">        List&lt;VideoBean&gt; vbl = new ArrayList&lt;&gt;();</span><br><span class="line">        VideoBean bean = null;</span><br><span class="line">        while (cursor.moveToNext())&#123;</span><br><span class="line">            bean = new VideoBean();</span><br><span class="line">            bean.chapterId = cursor.getInt(cursor.getColumnIndex(&quot;chapterId&quot;));</span><br><span class="line">            bean.videoId = cursor.getInt(cursor.getColumnIndex(&quot;videoId&quot;));</span><br><span class="line">            bean.videoPath = cursor.getString(cursor.getColumnIndex(&quot;videoPath&quot;));</span><br><span class="line">            bean.title = cursor.getString(cursor.getColumnIndex(&quot;title&quot;));</span><br><span class="line">            bean.secondTitle = cursor.getString(cursor.getColumnIndex(&quot;secondTitle&quot;));</span><br><span class="line">            vbl.add(bean);</span><br><span class="line">            bean = null;</span><br><span class="line">        &#125;</span><br><span class="line">        cursor.close();</span><br><span class="line">        return vbl;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>适配器代码：<br>VideoListItemAdapter.java </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.adapter;</span><br><span class="line"></span><br><span class="line">import android.app.Activity;</span><br><span class="line">import android.content.Context;</span><br><span class="line">import android.content.Intent;</span><br><span class="line">import android.content.SharedPreferences;</span><br><span class="line">import android.graphics.Color;</span><br><span class="line">import android.text.TextUtils;</span><br><span class="line">import android.view.LayoutInflater;</span><br><span class="line">import android.view.View;</span><br><span class="line">import android.view.ViewGroup;</span><br><span class="line">import android.widget.BaseAdapter;</span><br><span class="line">import android.widget.ImageView;</span><br><span class="line">import android.widget.TextView;</span><br><span class="line">import android.widget.Toast;</span><br><span class="line"></span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Activity.VideoPlayActivity;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Bean.VideoBean;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.R;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.utils.AnalysisUtils;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.utils.DBUtils;</span><br><span class="line"></span><br><span class="line">public class VideoListItemAdapter extends BaseAdapter &#123;</span><br><span class="line"></span><br><span class="line">    private List&lt;VideoBean&gt; objects = new ArrayList&lt;VideoBean&gt;();</span><br><span class="line">    private int selectedPosition = -1;</span><br><span class="line"></span><br><span class="line">    private DBUtils db;</span><br><span class="line">    private Context context;</span><br><span class="line">    private LayoutInflater layoutInflater;</span><br><span class="line"></span><br><span class="line">    public VideoListItemAdapter(Context context) &#123;</span><br><span class="line">        this.context = context;</span><br><span class="line">        this.layoutInflater = LayoutInflater.from(context);</span><br><span class="line">        db = DBUtils.getInstance(context);</span><br><span class="line">    &#125;</span><br><span class="line">    public void setData(List&lt;VideoBean&gt; vbl)&#123;</span><br><span class="line">        this.objects = vbl;</span><br><span class="line">        notifyDataSetChanged();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public int getCount() &#123;</span><br><span class="line">        return objects.size();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setSelectedPosition(int position)&#123;</span><br><span class="line">        selectedPosition = position;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public VideoBean getItem(int position) &#123;</span><br><span class="line">        return objects.get(position);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public long getItemId(int position) &#123;</span><br><span class="line">        return position;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public View getView(int position, View convertView, ViewGroup parent) &#123;</span><br><span class="line">        if (convertView == null) &#123;</span><br><span class="line">            convertView = layoutInflater.inflate(R.layout.video_list_item, null);</span><br><span class="line">            convertView.setTag(new ViewHolder(convertView));</span><br><span class="line">        &#125;</span><br><span class="line">        initializeViews((VideoBean)getItem(position), (ViewHolder) convertView.getTag(), position, convertView);</span><br><span class="line">        return convertView;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void initializeViews(final VideoBean object, final ViewHolder holder, final int position, View convertView) &#123;</span><br><span class="line">        holder.ivLeftIcon.setImageResource(R.drawable.course_bar_icon);</span><br><span class="line">        holder.tvVideoTitle.setTextColor(Color.parseColor(&quot;#333333&quot;));</span><br><span class="line">        if (object != null)&#123;</span><br><span class="line">            holder.tvVideoTitle.setText(object.secondTitle);</span><br><span class="line">            if (selectedPosition == position)&#123;</span><br><span class="line">                holder.ivLeftIcon.setImageResource(R.drawable.course_intro_icon);;</span><br><span class="line">                holder.tvVideoTitle.setTextColor(Color.parseColor(&quot;$009958&quot;));</span><br><span class="line">            &#125;else &#123;</span><br><span class="line">                holder.ivLeftIcon.setImageResource(R.drawable.course_bar_icon);</span><br><span class="line">                holder.tvVideoTitle.setTextColor(Color.parseColor(&quot;#333333&quot;));</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        convertView.setOnClickListener(new View.OnClickListener() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public void onClick(View v) &#123;</span><br><span class="line">                setSelectedPosition(position);</span><br><span class="line">                if (object != null)&#123;</span><br><span class="line">                    String videoPath = object.videoPath;</span><br><span class="line">                    notifyDataSetChanged();</span><br><span class="line">                    if (TextUtils.isEmpty(videoPath))&#123;</span><br><span class="line">                        Toast.makeText(context, &quot;本地没有此视频，暂无法播放&quot;, Toast.LENGTH_SHORT).show();</span><br><span class="line">                    &#125;else &#123;</span><br><span class="line">                        if (readLoginStatus())&#123;</span><br><span class="line">                            String userName = AnalysisUtils.readLoginUserName(context);</span><br><span class="line">                            db.saveVideoPlayList(objects.get(position), userName);</span><br><span class="line">                        &#125;</span><br><span class="line">                        //视频播放</span><br><span class="line">                        Intent intent = new Intent(context, VideoPlayActivity.class);</span><br><span class="line">                        intent.putExtra(&quot;videoPath&quot;, videoPath);</span><br><span class="line">                        intent.putExtra(&quot;position&quot;, position);</span><br><span class="line">                        ((Activity) context).startActivityForResult(intent, 1);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">    private boolean readLoginStatus()&#123;</span><br><span class="line">        SharedPreferences sp = context.getSharedPreferences(&quot;loginInfo&quot;, Context.MODE_PRIVATE);</span><br><span class="line">        boolean isLogin = sp.getBoolean(&quot;isLogin&quot;, false);</span><br><span class="line">        return isLogin;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    protected class ViewHolder &#123;</span><br><span class="line">        private ImageView ivLeftIcon;</span><br><span class="line">        private TextView tvVideoTitle;</span><br><span class="line"></span><br><span class="line">        public ViewHolder(View view) &#123;</span><br><span class="line">            ivLeftIcon = (ImageView) view.findViewById(R.id.iv_left_icon);</span><br><span class="line">            tvVideoTitle = (TextView) view.findViewById(R.id.tv_video_title);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>课程详情界面逻辑代码<br>先把data.json文件放进assets文件夹。</p>
<p>VideoListActivity的逻辑代码</p>
<p>VideoListActivity.java </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.Activity;</span><br><span class="line"></span><br><span class="line">import android.app.Activity;</span><br><span class="line">import android.content.Intent;</span><br><span class="line">import android.graphics.Color;</span><br><span class="line">import android.os.Bundle;</span><br><span class="line">import android.view.View;</span><br><span class="line">import android.widget.ListView;</span><br><span class="line">import android.widget.ScrollView;</span><br><span class="line">import android.widget.TextView;</span><br><span class="line"></span><br><span class="line">import org.json.JSONArray;</span><br><span class="line">import org.json.JSONException;</span><br><span class="line">import org.json.JSONObject;</span><br><span class="line"></span><br><span class="line">import java.io.BufferedReader;</span><br><span class="line">import java.io.IOException;</span><br><span class="line">import java.io.InputStream;</span><br><span class="line">import java.io.InputStreamReader;</span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Bean.VideoBean;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.R;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.adapter.VideoListItemAdapter;</span><br><span class="line"></span><br><span class="line">public class VideoListActivity extends Activity&#123;</span><br><span class="line">    private TextView tvIntro;</span><br><span class="line">    private TextView tvVideo;</span><br><span class="line">    private ListView lvVideoList;</span><br><span class="line">    private ScrollView svChapterIntro;</span><br><span class="line">    private TextView tvChapterIntro;</span><br><span class="line">    private List&lt;VideoBean&gt; videoList;</span><br><span class="line">    private int chapterId;</span><br><span class="line">    private String intro;</span><br><span class="line">    private VideoListItemAdapter adapter;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void onCreate(Bundle savedInstanceState) &#123;</span><br><span class="line">        super.onCreate(savedInstanceState);</span><br><span class="line">        setContentView(R.layout.activity_video_list);</span><br><span class="line">        chapterId = getIntent().getIntExtra(&quot;id&quot;, 0);</span><br><span class="line">        intro = getIntent().getStringExtra(&quot;intro&quot;);</span><br><span class="line">        initData();</span><br><span class="line">        initView();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    //把json文件转换为字符串</span><br><span class="line">    private String read(InputStream is)&#123;</span><br><span class="line">        BufferedReader reader = null;</span><br><span class="line">        StringBuilder sb = null;</span><br><span class="line">        String line = null;</span><br><span class="line">        try&#123;</span><br><span class="line">            sb = new StringBuilder();</span><br><span class="line">            reader = new BufferedReader(new InputStreamReader(is));</span><br><span class="line">            while ((line = reader.readLine()) != null)&#123;</span><br><span class="line">                sb.append(line);</span><br><span class="line">                sb.append(&quot;\n&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;catch (IOException e)&#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">            return &quot;&quot;;</span><br><span class="line">        &#125;finally &#123;</span><br><span class="line">            if (is != null)&#123;</span><br><span class="line">                try&#123;</span><br><span class="line">                    is.close();</span><br><span class="line">                    if (reader != null)&#123;</span><br><span class="line">                        reader.close();</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;catch (IOException e)&#123;</span><br><span class="line">                    e.printStackTrace();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        return sb.toString();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    //解析json</span><br><span class="line">    private void initData() &#123;</span><br><span class="line">        JSONArray jsonArray;</span><br><span class="line">        try&#123;</span><br><span class="line">            InputStream is = getResources().getAssets().open(&quot;data.json&quot;);</span><br><span class="line">            jsonArray = new JSONArray(read(is));</span><br><span class="line">            videoList = new ArrayList&lt;VideoBean&gt;();</span><br><span class="line">            for (int i = 0; i &lt; jsonArray.length(); i++)&#123;</span><br><span class="line">                VideoBean bean = new VideoBean();</span><br><span class="line">                JSONObject jsonObj = jsonArray.getJSONObject(i);</span><br><span class="line">                if (jsonObj.getInt(&quot;chapterId&quot;) == chapterId)&#123;</span><br><span class="line">                    bean.chapterId = jsonObj.getInt(&quot;chapterId&quot;);</span><br><span class="line">                    bean.videoId = Integer.parseInt(jsonObj.getString(&quot;videoId&quot;));</span><br><span class="line">                    bean.title = jsonObj.getString(&quot;title&quot;);</span><br><span class="line">                    bean.secondTitle = jsonObj.getString(&quot;secondTitle&quot;);</span><br><span class="line">                    bean.videoPath = jsonObj.getString(&quot;videoPath&quot;);</span><br><span class="line">                    videoList.add(bean);</span><br><span class="line">                &#125;</span><br><span class="line">                bean = null;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;catch (IOException e)&#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;catch (JSONException e)&#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void initView() &#123;</span><br><span class="line">        tvIntro = (TextView) findViewById(R.id.tv_intro);</span><br><span class="line">        tvVideo = (TextView) findViewById(R.id.tv_video);</span><br><span class="line">        lvVideoList = (ListView) findViewById(R.id.lv_video_list);</span><br><span class="line">        svChapterIntro = (ScrollView) findViewById(R.id.sv_chapter_intro);</span><br><span class="line">        tvChapterIntro = (TextView) findViewById(R.id.tv_chapter_intro);</span><br><span class="line">        adapter = new VideoListItemAdapter(this);</span><br><span class="line">        lvVideoList.setAdapter(adapter);</span><br><span class="line">        adapter.setData(videoList);</span><br><span class="line">        tvChapterIntro.setText(intro);</span><br><span class="line">        tvIntro.setBackgroundColor(Color.parseColor(&quot;#30B4FF&quot;));</span><br><span class="line">        tvVideo.setBackgroundColor(Color.parseColor(&quot;#FFFFFF&quot;));</span><br><span class="line">        tvIntro.setTextColor(Color.parseColor(&quot;#FFFFFF&quot;));</span><br><span class="line">        tvVideo.setTextColor(Color.parseColor(&quot;#000000&quot;));</span><br><span class="line">        tvIntro.setOnClickListener(new View.OnClickListener() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public void onClick(View v) &#123;</span><br><span class="line">                lvVideoList.setVisibility(View.GONE);</span><br><span class="line">                svChapterIntro.setVisibility(View.VISIBLE);</span><br><span class="line">                tvIntro.setBackgroundColor(Color.parseColor(&quot;#30B4FF&quot;));</span><br><span class="line">                tvVideo.setBackgroundColor(Color.parseColor(&quot;#FFFFFF&quot;));</span><br><span class="line">                tvIntro.setTextColor(Color.parseColor(&quot;#FFFFFF&quot;));</span><br><span class="line">                tvVideo.setTextColor(Color.parseColor(&quot;#000000&quot;));</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">        tvVideo.setOnClickListener(new View.OnClickListener() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public void onClick(View v) &#123;</span><br><span class="line">                lvVideoList.setVisibility(View.VISIBLE);</span><br><span class="line">                svChapterIntro.setVisibility(View.GONE);</span><br><span class="line">                tvIntro.setBackgroundColor(Color.parseColor(&quot;#FFFFFF&quot;));</span><br><span class="line">                tvVideo.setBackgroundColor(Color.parseColor(&quot;#30B4FF&quot;));</span><br><span class="line">                tvIntro.setTextColor(Color.parseColor(&quot;#000000&quot;));</span><br><span class="line">                tvVideo.setTextColor(Color.parseColor(&quot;#FFFFFF&quot;));</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">    @Override</span><br><span class="line">    protected void onActivityResult(int requestCode, int resultCode, Intent data)&#123;</span><br><span class="line">        super.onActivityResult(requestCode,resultCode,data);</span><br><span class="line">        if (data != null)&#123;</span><br><span class="line">            int position = data.getIntExtra(&quot;position&quot;, 0);</span><br><span class="line">            adapter.setSelectedPosition(position);</span><br><span class="line">            lvVideoList.setVisibility(View.VISIBLE);</span><br><span class="line">            svChapterIntro.setVisibility(View.GONE);</span><br><span class="line">            tvIntro.setBackgroundColor(Color.parseColor(&quot;#FFFFFF&quot;));</span><br><span class="line">            tvVideo.setBackgroundColor(Color.parseColor(&quot;#30B4FF&quot;));</span><br><span class="line">            tvIntro.setTextColor(Color.parseColor(&quot;#000000&quot;));</span><br><span class="line">            tvVideo.setTextColor(Color.parseColor(&quot;#FFFFFF&quot;));</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>到CourseListItemAdapter.java中添加上跳转至视频详情页面的代码。<br>CourseListItemAdapter.java </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.adapter;</span><br><span class="line"></span><br><span class="line">import android.content.Context;</span><br><span class="line">import android.content.Intent;</span><br><span class="line">import android.support.v7.widget.RecyclerView;</span><br><span class="line">import android.view.LayoutInflater;</span><br><span class="line">import android.view.View;</span><br><span class="line">import android.view.ViewGroup;</span><br><span class="line">import android.widget.ImageView;</span><br><span class="line">import android.widget.TextView;</span><br><span class="line"></span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Activity.VideoListActivity;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Bean.CourseBean;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.R;</span><br><span class="line"></span><br><span class="line">public class CourseListItemAdapter extends RecyclerView.Adapter&lt;CourseListItemAdapter.ViewHolder&gt; &#123;</span><br><span class="line"></span><br><span class="line">    private List&lt;CourseBean&gt; objects = new ArrayList&lt;CourseBean&gt;();</span><br><span class="line">    private Context context;</span><br><span class="line">    private LayoutInflater layoutInflater;</span><br><span class="line"></span><br><span class="line">    public CourseListItemAdapter(Context context) &#123;</span><br><span class="line">        this.context = context;</span><br><span class="line">        this.layoutInflater = LayoutInflater.from(context);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) &#123;</span><br><span class="line">        LayoutInflater inflater = LayoutInflater.from(parent.getContext());</span><br><span class="line">        View view=inflater.inflate(R.layout.course_list_item,parent,false);</span><br><span class="line">        return new ViewHolder(view);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void onBindViewHolder(ViewHolder holder, int position)&#123;</span><br><span class="line">        initializeViews(objects.get(position), holder);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setData(List&lt;CourseBean&gt; objects)&#123;</span><br><span class="line">        this.objects=objects;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public long getItemId(int position) &#123;</span><br><span class="line">        return position;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public int getItemCount() &#123;</span><br><span class="line">        return objects.size();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void initializeViews(final CourseBean object, ViewHolder holder) &#123;</span><br><span class="line">        if (object != null)&#123;</span><br><span class="line">            holder.tvCourseImgTitle.setText(object.imgTitle);</span><br><span class="line">            holder.tvCourseTitle.setText(object.title);</span><br><span class="line">            switch (object.id)&#123;</span><br><span class="line">                case 1:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_1_icon);</span><br><span class="line">                    break;</span><br><span class="line">                case 2:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_2_icon);</span><br><span class="line">                    break;</span><br><span class="line">                case 3:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_3_icon);</span><br><span class="line">                    break;</span><br><span class="line">                case 4:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_4_icon);</span><br><span class="line">                    break;</span><br><span class="line">                case 5:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_5_icon);</span><br><span class="line">                    break;</span><br><span class="line">                case 6:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_6_icon);</span><br><span class="line">                    break;</span><br><span class="line">                case 7:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_7_icon);</span><br><span class="line">                    break;</span><br><span class="line">                case 8:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_8_icon);</span><br><span class="line">                    break;</span><br><span class="line">                case 9:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_9_icon);</span><br><span class="line">                    break;</span><br><span class="line">                case 10:</span><br><span class="line">                    holder.ivCourseImg.setImageResource(R.drawable.chapter_10_icon);</span><br><span class="line">                    break;</span><br><span class="line">            &#125;</span><br><span class="line">            holder.ivCourseImg.setOnClickListener(new View.OnClickListener() &#123;</span><br><span class="line">                @Override</span><br><span class="line">                public void onClick(View v) &#123;</span><br><span class="line">                    Intent intent = new Intent(context, VideoListActivity.class);</span><br><span class="line">                    intent.putExtra(&quot;id&quot;, object.id);</span><br><span class="line">                    intent.putExtra(&quot;intro&quot;, object.intro);</span><br><span class="line">                    context.startActivity(intent);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    protected class ViewHolder extends RecyclerView.ViewHolder &#123;</span><br><span class="line">        private ImageView ivCourseImg;</span><br><span class="line">        private TextView tvCourseImgTitle;</span><br><span class="line">        private TextView tvCourseTitle;</span><br><span class="line"></span><br><span class="line">        public ViewHolder(View view) &#123;</span><br><span class="line">            super(view);</span><br><span class="line">            ivCourseImg = (ImageView) view.findViewById(R.id.iv_course_img);</span><br><span class="line">            tvCourseImgTitle = (TextView) view.findViewById(R.id.tv_course_img_title);</span><br><span class="line">            tvCourseTitle = (TextView) view.findViewById(R.id.tv_course_title);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>再到AndroidManifest.xml中声明activity </p>
<p>视频播放<br>视频播放布局<br>新建布局文件，命名为activity_video_play。</p>
<p>activity_video_play.xml </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;RelativeLayout</span><br><span class="line">    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span><br><span class="line">    android:layout_width=&quot;match_parent&quot;</span><br><span class="line">    android:layout_height=&quot;match_parent&quot;&gt;</span><br><span class="line">    &lt;VideoView</span><br><span class="line">        android:id=&quot;@+id/videoView&quot;</span><br><span class="line">        android:layout_width=&quot;match_parent&quot;</span><br><span class="line">        android:layout_height=&quot;match_parent&quot; /&gt;</span><br><span class="line">&lt;/RelativeLayout&gt;</span><br></pre></td></tr></table></figure>
<p>视频播放逻辑代码</p>
<p>VideoPlayActivity.java </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.Activity;</span><br><span class="line"></span><br><span class="line">import android.app.Activity;</span><br><span class="line">import android.content.Intent;</span><br><span class="line">import android.content.pm.ActivityInfo;</span><br><span class="line">import android.os.Bundle;</span><br><span class="line">import android.text.TextUtils;</span><br><span class="line">import android.view.KeyEvent;</span><br><span class="line">import android.widget.MediaController;</span><br><span class="line">import android.widget.Toast;</span><br><span class="line">import android.widget.VideoView;</span><br><span class="line"></span><br><span class="line">import cn.edu.gdmec.android.vicdemo.R;</span><br><span class="line"></span><br><span class="line">public class VideoPlayActivity extends Activity &#123;</span><br><span class="line"></span><br><span class="line">    private VideoView videoView;</span><br><span class="line">    private MediaController controller;</span><br><span class="line">    private String videoPath;</span><br><span class="line">    private int position;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void onCreate(Bundle savedInstanceState) &#123;</span><br><span class="line">        super.onCreate(savedInstanceState);</span><br><span class="line">        setContentView(R.layout.activity_video_play);</span><br><span class="line">        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);</span><br><span class="line">        videoPath = getIntent().getStringExtra(&quot;videoPath&quot;);</span><br><span class="line">        position = getIntent().getIntExtra(&quot;position&quot;, 0);</span><br><span class="line">        videoView = findViewById(R.id.videoView);</span><br><span class="line">        controller = new MediaController(this);</span><br><span class="line">        videoView.setMediaController(controller);</span><br><span class="line">        play();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void play() &#123;</span><br><span class="line">        if(TextUtils.isEmpty(videoPath))&#123;</span><br><span class="line">            Toast.makeText(this,&quot;本地没有此视频，暂无法播放&quot;, Toast.LENGTH_SHORT).show();</span><br><span class="line">            return;</span><br><span class="line">        &#125;</span><br><span class="line">        String uri = &quot;android.resource://&quot; + getPackageName() + &quot;/&quot; + R.raw.video11;</span><br><span class="line">        videoView.setVideoPath(uri);</span><br><span class="line">        videoView.start();</span><br><span class="line">    &#125;</span><br><span class="line">    @Override</span><br><span class="line">    public boolean onKeyDown(int keyCode, KeyEvent event)&#123;</span><br><span class="line">        Intent data = new Intent();</span><br><span class="line">        data.putExtra(&quot;position&quot;, position);</span><br><span class="line">        setResult(RESULT_OK, data);</span><br><span class="line">        return super.onKeyDown(keyCode, event);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>到VideoListItemAdapter.java里补上跳转视频播放页面的代码。<br>VideoListItemAdapter.java </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">//视频播放</span><br><span class="line">Intent intent = new Intent(context, VideoPlayActivity.class);</span><br><span class="line">intent.putExtra(&quot;videoPath&quot;, videoPath);</span><br><span class="line">intent.putExtra(&quot;position&quot;, position);</span><br><span class="line">((Activity) context).startActivityForResult(intent, 1);</span><br></pre></td></tr></table></figure>
<p>到AndroidManifest.xml中声明activity </p>
<h2 id="播放记录"><a href="#播放记录" class="headerlink" title="播放记录"></a>播放记录</h2><p>播放记录布局<br>新建布局文件，命名为activity_play_history</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span><br><span class="line">    android:orientation=&quot;vertical&quot;</span><br><span class="line">    android:layout_width=&quot;match_parent&quot;</span><br><span class="line">    android:layout_height=&quot;match_parent&quot;</span><br><span class="line">    android:background=&quot;@android:color/white&quot;&gt;</span><br><span class="line">    &lt;include layout=&quot;@layout/main_title_bar&quot;/&gt;</span><br><span class="line">    &lt;RelativeLayout</span><br><span class="line">        android:layout_width=&quot;match_parent&quot;</span><br><span class="line">        android:layout_height=&quot;match_parent&quot;&gt;</span><br><span class="line">        &lt;ListView</span><br><span class="line">            android:id=&quot;@+id/lv_list&quot;</span><br><span class="line">            android:layout_width=&quot;match_parent&quot;</span><br><span class="line">            android:layout_height=&quot;match_parent&quot;</span><br><span class="line">            android:divider=&quot;#E4E4E4&quot;</span><br><span class="line">            android:dividerHeight=&quot;1dp&quot;</span><br><span class="line">            android:scrollbars=&quot;none&quot;/&gt;</span><br><span class="line">        &lt;TextView</span><br><span class="line">            android:id=&quot;@+id/tv_none&quot;</span><br><span class="line">            android:layout_width=&quot;match_parent&quot;</span><br><span class="line">            android:layout_height=&quot;match_parent&quot;</span><br><span class="line">            android:gravity=&quot;center&quot;</span><br><span class="line">            android:text=&quot;暂无播放记录&quot;</span><br><span class="line">            android:textColor=&quot;@android:color/darker_gray&quot;</span><br><span class="line">            android:textSize=&quot;16sp&quot;</span><br><span class="line">            android:visibility=&quot;gone&quot;/&gt;</span><br><span class="line">    &lt;/RelativeLayout&gt;</span><br><span class="line">&lt;/LinearLayout&gt;</span><br></pre></td></tr></table></figure>
<p>播放记录item<br>新建布局文件，命名为play_history_list_item<br>play_history_list_item.xml </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span><br><span class="line">    android:layout_width=&quot;match_parent&quot;</span><br><span class="line">    android:layout_height=&quot;wrap_content&quot;</span><br><span class="line">    android:orientation=&quot;horizontal&quot;</span><br><span class="line">    android:background=&quot;@android:color/white&quot;</span><br><span class="line">    android:gravity=&quot;center_vertical&quot;</span><br><span class="line">    android:padding=&quot;10dp&quot;&gt;</span><br><span class="line">    &lt;RelativeLayout</span><br><span class="line">        android:layout_width=&quot;wrap_content&quot;</span><br><span class="line">        android:layout_height=&quot;wrap_content&quot;&gt;</span><br><span class="line">        &lt;ImageView</span><br><span class="line">            android:id=&quot;@+id/iv_video_icon&quot;</span><br><span class="line">            android:layout_width=&quot;100dp&quot;</span><br><span class="line">            android:layout_height=&quot;75dp&quot;</span><br><span class="line">            android:src=&quot;@drawable/video_play_icon2&quot;/&gt;</span><br><span class="line">        &lt;ImageView</span><br><span class="line">            android:layout_width=&quot;30dp&quot;</span><br><span class="line">            android:layout_height=&quot;30dp&quot;</span><br><span class="line">            android:src=&quot;@android:drawable/ic_media_play&quot;/&gt;</span><br><span class="line">    &lt;/RelativeLayout&gt;</span><br><span class="line">    &lt;LinearLayout</span><br><span class="line">        android:layout_width=&quot;match_parent&quot;</span><br><span class="line">        android:layout_height=&quot;wrap_content&quot;</span><br><span class="line">        android:orientation=&quot;vertical&quot;</span><br><span class="line">        android:layout_marginLeft=&quot;15dp&quot;</span><br><span class="line">        android:layout_gravity=&quot;center_vertical&quot;&gt;</span><br><span class="line">        &lt;TextView</span><br><span class="line">            android:id=&quot;@+id/tv_adapter_title&quot;</span><br><span class="line">            android:layout_width=&quot;wrap_content&quot;</span><br><span class="line">            android:layout_height=&quot;match_parent&quot;</span><br><span class="line">            android:textSize=&quot;16sp&quot;</span><br><span class="line">            android:textColor=&quot;#333333&quot;</span><br><span class="line">            android:text=&quot;第1章 Android基础入门&quot;</span><br><span class="line">            android:gravity=&quot;center_vertical&quot;/&gt;</span><br><span class="line">        &lt;TextView</span><br><span class="line">            android:layout_marginTop=&quot;4dp&quot;</span><br><span class="line">            android:id=&quot;@+id/tv_video_title&quot;</span><br><span class="line">            android:layout_width=&quot;wrap_content&quot;</span><br><span class="line">            android:layout_height=&quot;match_parent&quot;</span><br><span class="line">            android:textSize=&quot;12sp&quot;</span><br><span class="line">            android:textColor=&quot;#a3a3a3&quot;</span><br><span class="line">            android:text=&quot;Android系统简介&quot;</span><br><span class="line">            android:gravity=&quot;center_vertical&quot;/&gt;</span><br><span class="line">    &lt;/LinearLayout&gt;</span><br><span class="line">&lt;/LinearLayout&gt;</span><br></pre></td></tr></table></figure>
<h2 id="播放记录adapter"><a href="#播放记录adapter" class="headerlink" title="播放记录adapter"></a>播放记录adapter</h2><p>PlayHistoryListItemAdapter.java<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.adapter;</span><br><span class="line"></span><br><span class="line">import android.content.Context;</span><br><span class="line">import android.content.Intent;</span><br><span class="line">import android.view.LayoutInflater;</span><br><span class="line">import android.view.View;</span><br><span class="line">import android.view.ViewGroup;</span><br><span class="line">import android.widget.BaseAdapter;</span><br><span class="line">import android.widget.ImageView;</span><br><span class="line">import android.widget.TextView;</span><br><span class="line"></span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Activity.VideoPlayActivity;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Bean.VideoBean;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.R;</span><br><span class="line"></span><br><span class="line">public class PlayHistoryListItemAdapter extends BaseAdapter &#123;</span><br><span class="line"></span><br><span class="line">    private List&lt;VideoBean&gt; objects = new ArrayList&lt;VideoBean&gt;();</span><br><span class="line"></span><br><span class="line">    private Context context;</span><br><span class="line">    private LayoutInflater layoutInflater;</span><br><span class="line"></span><br><span class="line">    public PlayHistoryListItemAdapter(Context context) &#123;</span><br><span class="line">        this.context = context;</span><br><span class="line">        this.layoutInflater = LayoutInflater.from(context);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setData(List&lt;VideoBean&gt; vbl)&#123;</span><br><span class="line">        this.objects = vbl;</span><br><span class="line">        notifyDataSetChanged();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public int getCount() &#123;</span><br><span class="line">        return objects.size();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public VideoBean getItem(int position) &#123;</span><br><span class="line">        return objects.get(position);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public long getItemId(int position) &#123;</span><br><span class="line">        return position;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public View getView(int position, View convertView, ViewGroup parent) &#123;</span><br><span class="line">        if (convertView == null) &#123;</span><br><span class="line">            convertView = layoutInflater.inflate(R.layout.play_history_list_item, null);</span><br><span class="line">            convertView.setTag(new ViewHolder(convertView));</span><br><span class="line">        &#125;</span><br><span class="line">        initializeViews((VideoBean)getItem(position), (ViewHolder) convertView.getTag(), convertView);</span><br><span class="line">        return convertView;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void initializeViews(final VideoBean object, ViewHolder holder, final View convertView) &#123;</span><br><span class="line">        if (object != null)&#123;</span><br><span class="line">            holder.tvAdapterTitle.setText(object.title);</span><br><span class="line">            holder.tvVideoTitle.setText(object.secondTitle);</span><br><span class="line">            switch (object.chapterId)&#123;</span><br><span class="line">                case 1:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon1);</span><br><span class="line">                    break;</span><br><span class="line">                case 2:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon2);</span><br><span class="line">                    break;</span><br><span class="line">                case 3:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon3);</span><br><span class="line">                    break;</span><br><span class="line">                case 4:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon4);</span><br><span class="line">                    break;</span><br><span class="line">                case 5:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon5);</span><br><span class="line">                    break;</span><br><span class="line">                case 6:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon6);</span><br><span class="line">                    break;</span><br><span class="line">                case 7:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon7);</span><br><span class="line">                    break;</span><br><span class="line">                case 8:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon8);</span><br><span class="line">                    break;</span><br><span class="line">                case 9:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon9);</span><br><span class="line">                    break;</span><br><span class="line">                case 10:</span><br><span class="line">                    holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon10);</span><br><span class="line">                    break;</span><br><span class="line">                    default:</span><br><span class="line">                        holder.ivVideoIcon.setImageResource(R.drawable.video_play_icon1);</span><br><span class="line">                        break;</span><br><span class="line">            &#125;</span><br><span class="line">            convertView.setOnClickListener(new View.OnClickListener() &#123;</span><br><span class="line">                @Override</span><br><span class="line">                public void onClick(View v) &#123;</span><br><span class="line">                    if (object == null)&#123;</span><br><span class="line">                        return;</span><br><span class="line">                    &#125;</span><br><span class="line">                    Intent intent = new Intent(context, VideoPlayActivity.class);</span><br><span class="line">                    intent.putExtra(&quot;videoPath&quot;, object.videoPath);</span><br><span class="line">                    context.startActivity(intent);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    protected class ViewHolder &#123;</span><br><span class="line">        private ImageView ivVideoIcon;</span><br><span class="line">        private TextView tvAdapterTitle;</span><br><span class="line">        private TextView tvVideoTitle;</span><br><span class="line"></span><br><span class="line">        public ViewHolder(View view) &#123;</span><br><span class="line">            ivVideoIcon = (ImageView) view.findViewById(R.id.iv_video_icon);</span><br><span class="line">            tvAdapterTitle = (TextView) view.findViewById(R.id.tv_adapter_title);</span><br><span class="line">            tvVideoTitle = (TextView) view.findViewById(R.id.tv_video_title);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="播放记录逻辑代码"><a href="#播放记录逻辑代码" class="headerlink" title="播放记录逻辑代码"></a>播放记录逻辑代码</h2><p>PlayHistoryActivity.java </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.Activity;</span><br><span class="line"></span><br><span class="line">import android.app.Activity;</span><br><span class="line">import android.graphics.Color;</span><br><span class="line">import android.os.Bundle;</span><br><span class="line">import android.view.View;</span><br><span class="line">import android.widget.ListView;</span><br><span class="line">import android.widget.RelativeLayout;</span><br><span class="line">import android.widget.TextView;</span><br><span class="line"></span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">import cn.edu.gdmec.android.vicdemo.Bean.VideoBean;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.R;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.adapter.PlayHistoryListItemAdapter;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.utils.AnalysisUtils;</span><br><span class="line">import cn.edu.gdmec.android.vicdemo.utils.DBUtils;</span><br><span class="line"></span><br><span class="line">public class PlayHistoryActivity extends Activity &#123;</span><br><span class="line"></span><br><span class="line">    private TextView tv_back;</span><br><span class="line">    private TextView tv_main_title;</span><br><span class="line">    private TextView tv_save;</span><br><span class="line">    private RelativeLayout title_bar;</span><br><span class="line">    private ListView lv_list;</span><br><span class="line">    private TextView tv_none;</span><br><span class="line">    private List&lt;VideoBean&gt; vbl;</span><br><span class="line">    private DBUtils db;</span><br><span class="line">    private PlayHistoryListItemAdapter adapter;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void onCreate(Bundle savedInstanceState) &#123;</span><br><span class="line">        super.onCreate(savedInstanceState);</span><br><span class="line">        setContentView(R.layout.activity_play_history);</span><br><span class="line">        db = DBUtils.getInstance(this);</span><br><span class="line">        vbl = new ArrayList&lt;VideoBean&gt;();</span><br><span class="line">        vbl = db.getVideoHistory(AnalysisUtils.readLoginUserName(this));</span><br><span class="line">        initView();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void initView() &#123;</span><br><span class="line">        tv_back = findViewById(R.id.tv_back);</span><br><span class="line">        tv_main_title = findViewById(R.id.tv_main_title);</span><br><span class="line">        tv_save = findViewById(R.id.tv_save);</span><br><span class="line">        title_bar = findViewById(R.id.title_bar);</span><br><span class="line">        lv_list = findViewById(R.id.lv_list);</span><br><span class="line">        tv_none = findViewById(R.id.tv_none);</span><br><span class="line">        tv_main_title.setText(&quot;播放记录&quot;);</span><br><span class="line">        title_bar.setBackgroundColor(Color.parseColor(&quot;#30B4FF&quot;));</span><br><span class="line">        if (vbl.size() == 0)&#123;</span><br><span class="line">            tv_none.setVisibility(View.VISIBLE);</span><br><span class="line">        &#125;</span><br><span class="line">        adapter = new PlayHistoryListItemAdapter(this);</span><br><span class="line">        adapter.setData(vbl);</span><br><span class="line">        lv_list.setAdapter(adapter);</span><br><span class="line">        tv_back.setOnClickListener(new View.OnClickListener() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public void onClick(View v) &#123;</span><br><span class="line">                PlayHistoryActivity.this.fileList();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>MyinfoFragment.java里补上跳转视频播放页面的代码。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">//跳转到播放记录页面</span><br><span class="line">                    Intent intent = new Intent(getActivity(), PlayHistoryActivity.class);</span><br><span class="line">                    getActivity().startActivity(intent);</span><br></pre></td></tr></table></figure>
<p>到AndroidManifest.xml中声明activity<br>AndroidManifest.xml </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span><br><span class="line">    package=&quot;cn.edu.gdmec.android.vicdemo&quot;&gt;</span><br><span class="line"></span><br><span class="line">    &lt;application</span><br><span class="line">        android:allowBackup=&quot;true&quot;</span><br><span class="line">        android:icon=&quot;@drawable/app_icon&quot;</span><br><span class="line">        android:label=&quot;@string/app_name&quot;</span><br><span class="line">        android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;</span><br><span class="line">        android:supportsRtl=&quot;true&quot;</span><br><span class="line">        android:theme=&quot;@style/Theme.AppCompat.NoActionBar&quot;&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.SplashActivity&quot;&gt;</span><br><span class="line">            &lt;intent-filter&gt;</span><br><span class="line">                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;</span><br><span class="line">                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;</span><br><span class="line">            &lt;/intent-filter&gt;</span><br><span class="line">        &lt;/activity&gt;</span><br><span class="line">        &lt;!--添加实现类--&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.MainActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.RegisterActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.LoginActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.SettingActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.ModifyPswActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.FindPwdActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.UserInfoActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.ChangeUserInfoActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.ExercisesDetailActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.VideoListActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.VideoPlayActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">        &lt;activity android:name=&quot;.Activity.PlayHistoryActivity&quot;&gt;&lt;/activity&gt;</span><br><span class="line">    &lt;/application&gt;</span><br><span class="line">&lt;/manifest&gt;</span><br></pre></td></tr></table></figure>
<h2 id="任务实施"><a href="#任务实施" class="headerlink" title="任务实施"></a>任务实施</h2><p>json解析<br>将res/assets包下的data.Json文件打开，把下面的json数据覆盖掉原来的数据，更改解析json数据的代码，把新的json数据解析出来并成功展示。</p>
<p>播放网络视频<br>修改VideoView控件和AndroidManifest.xml的代码，使其能成功播放下面json数据里的网络视频。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br></pre></td><td class="code"><pre><span class="line">json数据：</span><br><span class="line">[&#123;</span><br><span class="line"> &quot;chapterId&quot;: 1,</span><br><span class="line"> &quot;data&quot;: [</span><br><span class="line">  &#123;</span><br><span class="line">   &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">   &quot;title&quot;: &quot;第1章 Android 基础入门&quot;,</span><br><span class="line">   &quot;secondTitle&quot;: &quot;迷情巧克力&quot;,</span><br><span class="line">   &quot;videoPath&quot;: &quot;https://gslb.miaopai.com/stream/PaGWXOMYz-rMWm-r9a2MvILINHMc0YBXe2i-dg__.mp4?ssig=acb6880de7200e266864581d97c0654d&amp;time_stamp=1524887992615&amp;cookie_id=&amp;vend=1&amp;os=3&amp;partner=1&amp;platform=2&amp;cookie_id=&amp;refer=miaopai&amp;scid=PaGWXOMYz-rMWm-r9a2MvILINHMc0YBXe2i-dg__&quot;</span><br><span class="line">  &#125;,</span><br><span class="line">  &#123;</span><br><span class="line">   &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">   &quot;title&quot;: &quot;第1章 Android 基础入门&quot;,</span><br><span class="line">   &quot;secondTitle&quot;: &quot;命运是什么&quot;,</span><br><span class="line">   &quot;videoPath&quot;: &quot;https://gslb.miaopai.com/stream/KP7xXv0IllZsjnK1HjVlkbGfb5yWj7mPbaEOmQ__.mp4?ssig=7d445a22609119e57b50c8fa9a84a11b&amp;time_stamp=1524888071281&amp;cookie_id=&amp;vend=1&amp;os=3&amp;partner=1&amp;platform=2&amp;cookie_id=&amp;refer=miaopai&amp;scid=KP7xXv0IllZsjnK1HjVlkbGfb5yWj7mPbaEOmQ__&quot;</span><br><span class="line">  &#125;</span><br><span class="line"> ]</span><br><span class="line">&#125;,</span><br><span class="line"> &#123;</span><br><span class="line">  &quot;chapterId&quot;: 2,</span><br><span class="line">  &quot;data&quot;: [</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第2章 Android UI开发&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;水银为什么是液体&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;https://gslb.miaopai.com/stream/cnngO-Co7rFlVPzkS7qqoaxR7OFH72uvYDDiew__.mp4?ssig=b91b143afbaadb8472b57b17e0c213e5&amp;time_stamp=1524888092840&amp;cookie_id=&amp;vend=1&amp;os=3&amp;partner=1&amp;platform=2&amp;cookie_id=&amp;refer=miaopai&amp;scid=cnngO-Co7rFlVPzkS7qqoaxR7OFH72uvYDDiew__&quot;</span><br><span class="line">   &#125;,</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第2章 Android UI开发&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;汽车的历史&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;https://gslb.miaopai.com/stream/6S23U5PMRtOQzu99NeITYztd0xtKFW2xDYxwXQ__.mp4?ssig=afa07a802aca690154953446fc5de4d4&amp;time_stamp=1524888118545&amp;cookie_id=&amp;vend=1&amp;os=3&amp;partner=1&amp;platform=2&amp;cookie_id=&amp;refer=miaopai&amp;scid=6S23U5PMRtOQzu99NeITYztd0xtKFW2xDYxwXQ__&quot;</span><br><span class="line">   &#125;</span><br><span class="line">  ]</span><br><span class="line"> &#125;,</span><br><span class="line"> &#123;</span><br><span class="line">  &quot;chapterId&quot;: 3,</span><br><span class="line">  &quot;data&quot;: [</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第3章 Activity&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;汽车的历史&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;https://gslb.miaopai.com/stream/6S23U5PMRtOQzu99NeITYztd0xtKFW2xDYxwXQ__.mp4?ssig=afa07a802aca690154953446fc5de4d4&amp;time_stamp=1524888118545&amp;cookie_id=&amp;vend=1&amp;os=3&amp;partner=1&amp;platform=2&amp;cookie_id=&amp;refer=miaopai&amp;scid=6S23U5PMRtOQzu99NeITYztd0xtKFW2xDYxwXQ__&quot;</span><br><span class="line">   &#125;,</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;chapterId&quot;: 3,</span><br><span class="line">    &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第3章 Activity&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;Activity中的数据传递&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;</span><br><span class="line">  ]</span><br><span class="line"> &#125;,</span><br><span class="line"> &#123;</span><br><span class="line">  &quot;chapterId&quot;: 4,</span><br><span class="line">  &quot;data&quot;: [</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第4章 数据存储&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;文件存储&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;,</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第4章 数据存储&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;XML序列化与SharedPreferences&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;</span><br><span class="line">  ]</span><br><span class="line"> &#125;,</span><br><span class="line"> &#123;</span><br><span class="line">  &quot;chapterId&quot;: 5,</span><br><span class="line">  &quot;data&quot;: [</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第5章 SQLite 数据库&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;SQLite数据库的使用&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;,</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第5章 SQLite 数据库&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;ListView控件的使用&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;</span><br><span class="line">  ]</span><br><span class="line"> &#125;,</span><br><span class="line"> &#123;</span><br><span class="line">  &quot;chapterId&quot;: 6,</span><br><span class="line">  &quot;data&quot;: [</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第6章 广播接收者&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;内容提供者简介&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;,</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第6章 广播接收者&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;内容提供者的访问&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;</span><br><span class="line">  ]</span><br><span class="line"> &#125;,</span><br><span class="line"> &#123;</span><br><span class="line">  &quot;chapterId&quot;: 7,</span><br><span class="line">  &quot;data&quot;: [</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第7章 服务&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;广播接收者与自定义广播&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;,</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第7章 服务&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;广播类型与常用的广播接收者&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;</span><br><span class="line">  ]</span><br><span class="line"> &#125;,</span><br><span class="line"> &#123;</span><br><span class="line">  &quot;chapterId&quot;: 8,</span><br><span class="line">  &quot;data&quot;: [</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第8章 内容提供者&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;服务的创建与生命周期&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;,</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第8章 内容提供者&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;服务的启动方式&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;</span><br><span class="line">  ]</span><br><span class="line"> &#125;,</span><br><span class="line"> &#123;</span><br><span class="line">  &quot;chapterId&quot;: 9,</span><br><span class="line">  &quot;data&quot;: [</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第9章 网络编程&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;访问网络&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;,</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第9章 网络编程&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;数据的提交方式&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;</span><br><span class="line">  ]</span><br><span class="line"> &#125;,</span><br><span class="line"> &#123;</span><br><span class="line">  &quot;chapterId&quot;: 10,</span><br><span class="line">  &quot;data&quot;: [</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;1&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第10章 高级编程&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;图形图像处理与动画&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;,</span><br><span class="line">   &#123;</span><br><span class="line">    &quot;videoId&quot;: &quot;2&quot;,</span><br><span class="line">    &quot;title&quot;: &quot;第10章 高级编程&quot;,</span><br><span class="line">    &quot;secondTitle&quot;: &quot;多媒体、与Fragment&quot;,</span><br><span class="line">    &quot;videoPath&quot;: &quot;&quot;</span><br><span class="line">   &#125;</span><br><span class="line">  ]</span><br><span class="line"> &#125;</span><br><span class="line">]</span><br></pre></td></tr></table></figure>
<h2 id="总结-完"><a href="#总结-完" class="headerlink" title="总结 完"></a>总结 完</h2><h2 id="解决方法"><a href="#解决方法" class="headerlink" title="解决方法"></a>解决方法</h2><p>VideoListActivity </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">//解析json</span><br><span class="line">    private void initData() &#123;</span><br><span class="line">        //JSONArray jsonArray;</span><br><span class="line">        JSONArray jsonArray,jsonArray1;</span><br><span class="line">        List&lt;String&gt; list = new ArrayList&lt;String&gt;();</span><br><span class="line">        List&lt;VideoBean&gt; list1 = new ArrayList&lt;VideoBean&gt;();</span><br><span class="line"></span><br><span class="line">        try&#123;</span><br><span class="line">            InputStream is = getResources().getAssets().open(&quot;data.json&quot;);</span><br><span class="line">            jsonArray = new JSONArray(read(is));</span><br><span class="line">            videoList = new ArrayList&lt;VideoBean&gt;();</span><br><span class="line">            for (int i = 0; i &lt; jsonArray.length(); i++)&#123;</span><br><span class="line">                VideoBean bean = new VideoBean();</span><br><span class="line">                JSONObject jsonObj = jsonArray.getJSONObject(i);</span><br><span class="line">                if (jsonObj.getInt(&quot;chapterId&quot;) == chapterId)&#123;</span><br><span class="line">                    bean.chapterId = jsonObj.getInt(&quot;chapterId&quot;);</span><br><span class="line"></span><br><span class="line">                    /*bean.videoId = Integer.parseInt(jsonObj.getString(&quot;videoId&quot;));</span><br><span class="line">                    bean.title = jsonObj.getString(&quot;title&quot;);</span><br><span class="line">                    bean.secondTitle = jsonObj.getString(&quot;secondTitle&quot;);</span><br><span class="line">                    bean.videoPath = jsonObj.getString(&quot;videoPath&quot;);</span><br><span class="line">                    videoList.add(bean);*/</span><br><span class="line">                    String ss =jsonObj.getString(&quot;data&quot;);</span><br><span class="line">                    jsonArray1 = new JSONArray(ss);</span><br><span class="line">                    for (int j=0;j&lt;jsonArray1.length();j++)&#123;</span><br><span class="line">                        JSONObject jsonObject = (JSONObject) jsonArray1.get(j);</span><br><span class="line"></span><br><span class="line">                        Iterator&lt;String&gt; iterator = jsonObject.keys();</span><br><span class="line">                        while (iterator.hasNext())&#123;</span><br><span class="line">                            String key = iterator.next();</span><br><span class="line">                            String value = jsonObject.getString(key);</span><br><span class="line">                            list.add(value);</span><br><span class="line">                        &#125;</span><br><span class="line">                        bean.videoId = Integer.parseInt(list.get(0));</span><br><span class="line">                        bean.title = list.get(1);</span><br><span class="line">                        bean.secondTitle = list.get(2);</span><br><span class="line">                        bean.videoPath = list.get(3);</span><br><span class="line">                        videoList.add(bean);</span><br><span class="line">                        bean = new VideoBean();</span><br><span class="line">                        list.clear();</span><br><span class="line">                        Log.i(&quot;Ss&quot;,videoList.toString());</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                &#125;</span><br><span class="line">                bean = null;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;catch (IOException e)&#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;catch (JSONException e)&#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>VideoPlayActivity </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">package cn.edu.gdmec.android.vicdemo.Activity;</span><br><span class="line"></span><br><span class="line">import android.app.Activity;</span><br><span class="line">import android.content.Intent;</span><br><span class="line">import android.content.pm.ActivityInfo;</span><br><span class="line">import android.net.Uri;</span><br><span class="line">import android.os.Bundle;</span><br><span class="line">import android.text.TextUtils;</span><br><span class="line">import android.util.Log;</span><br><span class="line">import android.view.KeyEvent;</span><br><span class="line">import android.view.WindowManager;</span><br><span class="line">import android.widget.MediaController;</span><br><span class="line">import android.widget.Toast;</span><br><span class="line">import android.widget.VideoView;</span><br><span class="line"></span><br><span class="line">import cn.edu.gdmec.android.vicdemo.R;</span><br><span class="line"></span><br><span class="line">public class VideoPlayActivity extends Activity &#123;</span><br><span class="line"></span><br><span class="line">    private VideoView videoView;</span><br><span class="line">    private MediaController controller;</span><br><span class="line">    private String videoPath;</span><br><span class="line">    private int position;////传递视频详情界面点击的视频位置</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void onCreate(Bundle savedInstanceState) &#123;</span><br><span class="line">        super.onCreate(savedInstanceState);</span><br><span class="line">        //设置界面全屏显示</span><br><span class="line">        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);</span><br><span class="line">        setContentView(R.layout.activity_video_play);</span><br><span class="line">        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);</span><br><span class="line">        //获取从播放记录界面传递过来的视频地址</span><br><span class="line">        videoPath = getIntent().getStringExtra(&quot;videoPath&quot;);</span><br><span class="line">        position = getIntent().getIntExtra(&quot;position&quot;, 0);</span><br><span class="line"></span><br><span class="line">        videoView = findViewById(R.id.videoView);</span><br><span class="line">        controller = new MediaController(this);</span><br><span class="line">        videoView.setMediaController(controller);</span><br><span class="line">        play();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private void play() &#123;</span><br><span class="line">        if(TextUtils.isEmpty(videoPath))&#123;</span><br><span class="line">            Toast.makeText(this,&quot;本地没有此视频，暂无法播放&quot;, Toast.LENGTH_SHORT).show();</span><br><span class="line">            return;</span><br><span class="line">        &#125;</span><br><span class="line">        //String uri = &quot;android.resource://&quot; + getPackageName() + &quot;/&quot; + R.raw.video11;</span><br><span class="line">        Log.i(&quot;Video&quot;,videoPath);</span><br><span class="line">        String uri = videoPath;</span><br><span class="line">        Uri uri1 = Uri.parse(uri);</span><br><span class="line">        videoView.setVideoURI(uri1);</span><br><span class="line">        //videoView.setVideoPath(uri);</span><br><span class="line">        videoView.start();</span><br><span class="line">    &#125;</span><br><span class="line">    @Override</span><br><span class="line">    public boolean onKeyDown(int keyCode, KeyEvent event)&#123;</span><br><span class="line">        //把视频详情界面传递过来的被点击视频的位置传递回去</span><br><span class="line">        Intent data = new Intent();</span><br><span class="line">        data.putExtra(&quot;position&quot;, position);</span><br><span class="line">        setResult(RESULT_OK, data);</span><br><span class="line">        return super.onKeyDown(keyCode, event);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>大功告成！</p>
      
    </div>
    
    
    

      <div>
        
          <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
        
      </div>

    

      <div>
        <div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/images/微信公众号.jpg" alt="达叔小生 wechat" style="width: 200px; max-width: 100%">
    <div>欢迎您扫一扫上面的微信公众号，订阅我的博客！</div>
</div>

      </div>
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.png" alt="达叔小生 微信支付">
        <p>微信支付</p>
      </div>
    

    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    达叔小生
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://huangguangda.github.io/2018/04/28/1/" title="教育系统APP(八)">https://huangguangda.github.io/2018/04/28/1/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/教育系统APP/" rel="tag"><i class="fa fa-tag"></i> 教育系统APP</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/04/27/1/" rel="next" title="教育系统APP(七)">
                <i class="fa fa-chevron-left"></i> 教育系统APP(七)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/05/01/1/" rel="prev" title="Android应用基础知识">
                Android应用基础知识 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        
<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNTU5OC8xMjEzNA=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.gif" alt="达叔小生">
            
              <p class="site-author-name" itemprop="name">达叔小生</p>
              <p class="site-description motion-element" itemprop="description"></p>

            <div id="days"></div>
<script>
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("04/23/1997 00:00:00");
today=new Date();
timeold=(today.getTime()-BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=setzero(Math.floor(e_hrsold));
e_minsold=(e_hrsold-hrsold)*60;
minsold=setzero(Math.floor((e_hrsold-hrsold)*60));
seconds=setzero(Math.floor((e_minsold-minsold)*60));
document.getElementById('days').innerHTML="已运行"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";
}
function setzero(i){
if (i<10)
{i="0" + i};
return i;
}
show_date_time();
</script>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">94</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">20</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">21</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
                <a title="收藏到书签，偶尔High一下^_^" rel="alternate" class="mw-harlem_shake_slow wobble shake" href="javascript:(function() {
    function c() {
        var e = document.createElement(&quot;link&quot;);
        e.setAttribute(&quot;type&quot;, &quot;text/css&quot;);
        e.setAttribute(&quot;rel&quot;, &quot;stylesheet&quot;);
        e.setAttribute(&quot;href&quot;, f);
        e.setAttribute(&quot;class&quot;, l);
        document.body.appendChild(e)
    }
 
    function h() {
        var e = document.getElementsByClassName(l);
        for (var t = 0; t < e.length; t++) {
            document.body.removeChild(e[t])
        }
    }
 
    function p() {
        var e = document.createElement(&quot;div&quot;);
        e.setAttribute(&quot;class&quot;, a);
        document.body.appendChild(e);
        setTimeout(function() {
            document.body.removeChild(e)
        }, 100)
    }
 
    function d(e) {
        return {
            height : e.offsetHeight,
            width : e.offsetWidth
        }
    }
 
    function v(i) {
        var s = d(i);
        return s.height > e && s.height < n && s.width > t && s.width < r
    }
 
    function m(e) {
        var t = e;
        var n = 0;
        while (!!t) {
            n += t.offsetTop;
            t = t.offsetParent
        }
        return n
    }
 
    function g() {
        var e = document.documentElement;
        if (!!window.innerWidth) {
            return window.innerHeight
        } else if (e && !isNaN(e.clientHeight)) {
            return e.clientHeight
        }
        return 0
    }
 
    function y() {
        if (window.pageYOffset) {
            return window.pageYOffset
        }
        return Math.max(document.documentElement.scrollTop, document.body.scrollTop)
    }
 
    function E(e) {
        var t = m(e);
        return t >= w && t <= b + w
    }
 
    function S() {
        var e = document.createElement(&quot;audio&quot;);
        e.setAttribute(&quot;class&quot;, l);
        e.src = i;
        e.loop = false;
        e.addEventListener(&quot;canplay&quot;, function() {
            setTimeout(function() {
                x(k)
            }, 500);
            setTimeout(function() {
                N();
                p();
                for (var e = 0; e < O.length; e++) {
                    T(O[e])
                }
            }, 15500)
        }, true);
        e.addEventListener(&quot;ended&quot;, function() {
            N();
            h()
        }, true);
        e.innerHTML = &quot; <p>If you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.</p> <p>&quot;;
        document.body.appendChild(e);
        e.play()
    }
 
    function x(e) {
        e.className += &quot; &quot; + s + &quot; &quot; + o
    }
 
    function T(e) {
        e.className += &quot; &quot; + s + &quot; &quot; + u[Math.floor(Math.random() * u.length)]
    }
 
    function N() {
        var e = document.getElementsByClassName(s);
        var t = new RegExp(&quot;\\b&quot; + s + &quot;\\b&quot;);
        for (var n = 0; n < e.length; ) {
            e[n].className = e[n].className.replace(t, &quot;&quot;)
        }
    }
 
    var e = 30;
    var t = 30;
    var n = 350;
    var r = 350;
    var i = &quot;//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake.mp3&quot;;
    var s = &quot;mw-harlem_shake_me&quot;;
    var o = &quot;im_first&quot;;
    var u = [&quot;im_drunk&quot;, &quot;im_baked&quot;, &quot;im_trippin&quot;, &quot;im_blown&quot;];
    var a = &quot;mw-strobe_light&quot;;
    var f = &quot;//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake-style.css&quot;;
    var l = &quot;mw_added_css&quot;;
    var b = g();
    var w = y();
    var C = document.getElementsByTagName(&quot;*&quot;);
    var k = null;
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            if (E(A)) {
                k = A;
                break
            }
        }
    }
    if (A === null) {
        console.warn(&quot;Could not find a node of the right size. Please try a different page.&quot;);
        return
    }
    c();
    S();
    var O = [];
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            O.push(A)
        }
    }
})()"><i class="fa fa-music"></i> High</a>

            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/huangguangda" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:2397923107@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/c785ece603d1" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-android"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://blog.csdn.net/qq_36232611" target="_blank" title="csdn">
                      
                        <i class="fa fa-fw fa-spinner"></i>csdn</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.douban.com/people/186539024/" target="_blank" title="豆瓣">
                      
                        <i class="fa fa-fw fa-bath"></i>豆瓣</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/da-shu-xiao-sheng/activities" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-globe"></i>知乎</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/5a16e1f3f265da43128096cb" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-google"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/5507262458/profile?topnav=1&wvr=6" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-weibo"></i>微博</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzI1NTcxOTQ1Nw==&scene=124#wechat_redirect" target="_blank" title="历史">
                      
                        <i class="fa fa-fw fa-apple"></i>历史</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.cnblogs.com/dashucoding/" target="_blank" title="博客园">
                      
                        <i class="fa fa-fw fa-facebook"></i>博客园</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://gdone.gitee.io/englishpages/index.html" target="_blank" title="英文简历">
                      
                        <i class="fa fa-fw fa-globe"></i>英文简历</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://gdone.gitee.io/pages/" target="_blank" title="中文简历">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>中文简历</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://gitee.com/GDone/events" target="_blank" title="码云">
                      
                        <i class="fa fa-fw fa-twitter"></i>码云</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://my.oschina.net/xiaomaomi1997/" target="_blank" title="开源中国">
                      
                        <i class="fa fa-fw fa-facebook"></i>开源中国</a>
                  </span>
                
            </div>
          

          
          
            <div class="cc-license motion-element" itemprop="license">
              <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" target="_blank">
                <img src="/images/cc-by-nc-sa.svg" alt="Creative Commons">
              </a>
            </div>
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa fa-fw fa-globe"></i>
                推荐阅读
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.alloyteam.com/nav/" title="Web前端导航" target="_blank">Web前端导航</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.36zhen.com/t?id=3448" title="前端书籍资料" target="_blank">前端书籍资料</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://ife.baidu.com/" title="百度前端技术学院" target="_blank">百度前端技术学院</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://wf.uisdc.com/cn/" title="google前端开发基础" target="_blank">google前端开发基础</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.geekbang.org/" title="极客邦科技" target="_blank">极客邦科技</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://ilxdh.com/" title="龙轩导航" target="_blank">龙轩导航</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://code.giffox.com/" title="程序员导航" target="_blank">程序员导航</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://search.chongbuluo.com/" title="快搜" target="_blank">快搜</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.android-doc.com/training/index.html" title="Android中文API" target="_blank">Android中文API</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://developer.android.google.cn/" title="Android Developers" target="_blank">Android Developers</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.freecodecamp.cn/" title="FreeCodeCamp中文社区" target="_blank">FreeCodeCamp中文社区</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://docs.oracle.com/javase/specs/" title="Java SE规范" target="_blank">Java SE规范</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://liuwangshu.cn/" title="刘望舒" target="_blank">刘望舒</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.colabug.com/author/3159ee71c93b3b4a/" title="小楼昨夜又秋风" target="_blank">小楼昨夜又秋风</a>
                  </li>
                
              </ul>

            </div>
          


        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#项目“课程”的模块2"><span class="nav-number">1.</span> <span class="nav-text">项目“课程”的模块2</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#目录"><span class="nav-number">2.</span> <span class="nav-text">目录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#学习目标"><span class="nav-number">3.</span> <span class="nav-text">学习目标</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#项目实操"><span class="nav-number">4.</span> <span class="nav-text">项目实操</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#播放记录"><span class="nav-number">5.</span> <span class="nav-text">播放记录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#播放记录adapter"><span class="nav-number">6.</span> <span class="nav-text">播放记录adapter</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#播放记录逻辑代码"><span class="nav-number">7.</span> <span class="nav-text">播放记录逻辑代码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#任务实施"><span class="nav-number">8.</span> <span class="nav-text">任务实施</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结-完"><span class="nav-number">9.</span> <span class="nav-text">总结 完</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#解决方法"><span class="nav-number">10.</span> <span class="nav-text">解决方法</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="heart">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">达叔小生</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">357.6k</span>
  
</div>






  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共357.6k字</span>
</div>

<div class="weixin-box">
  <div class="weixin-menu">
    <div class="weixin-hover">
      <div class="weixin-description">微信扫一扫，订阅本博客</div>
    </div>
  </div>
</div>
        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">本站访客数</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">本站总访问量</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>





  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=65809965";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  



  
  









  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three-waves.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  


  <script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script>
<script type="text/javascript" src="/js/src/custom.js"></script>


   <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none"></canvas> 
   <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> 
   <script type="text/javascript" src="/js/src/fireworks.js"></script>


  <!-- 代码块复制功能 -->
  <script type="text/javascript" src="/js/src/clipboard.min.js"></script>  
  <script type="text/javascript" src="/js/src/clipboard-use.js"></script>
<script src="/live2dw/lib/L2Dwidget.min.js?0c58a1486de42ac6cc1c59c7d98ae887"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"live2d-widget-model-hibiki"},"display":{"position":"right","width":75,"height":150},"mobile":{"show":false},"log":false});</script></body>
</html>